<template>
  <el-row
    justify="space-between"
    type="flex"
    align="middle"
    style="height: 40px; width: 100%"
     
  >
    <!-- 左侧标题 -->
    <el-col>
      <span>{{ treeNode.name }}</span>
    </el-col>
    <!-- 右侧区域 -->
    <el-col :span="6">
      <el-row type="flex" justify="end">
        <el-col>{{treeNode.manager}}</el-col>
        <el-col>
          <el-dropdown  @command="handleCommand">
            <span>操作<i class="el-icon-arrow-down"></i></span>
            <el-dropdown-menu slot="dropdown">
             <el-dropdown-item command='add'> 添加子部门 </el-dropdown-item>
             <el-dropdown-item command='edit' v-if="!isRoot"> 编辑部门 </el-dropdown-item>
             <el-dropdown-item command='del' v-if="!isRoot"> 删除部门</el-dropdown-item>
            </el-dropdown-menu>
           
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>   
  </el-row>
</template>

<script>
import {Deldepartments} from '@/api/departments'
export default {
  props: {
    treeNode: {
      type: Object,
      required: true,
    },
    isRoot: {
      type: Boolean,
      required: false,
    },
  },
  data() {
    return {};
  },
  methods:{
   handleCommand(command){
     if(command==='add'){
      this.$emit('addDepts',this.treeNode)
     } 
     else if(command ==='edit'){
       this.$emit('editDepts',this.treeNode)
     }
     else{
        this.$confirm('您确定删除该组织部门吗？').then(()=>{
           return  Deldepartments(this.treeNode.id)
        }).then(()=>{
            this.$emit('delDepts') //子传父 触发自定义事件
            this.$message.success('删除部门成功')
        })
     }
   }
  }
};
</script>

<style>
</style>